package com.dci.controller.schedule;

import com.alibaba.fastjson.JSONObject;
import com.dci.model.schedule.ProgressTrack;
import com.dci.result.ResultInfo;
import com.dci.service.schedule.ProgressTrackService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller.project
 * @Description: 项目管理
 * @author: 张星亮
 * @date: 2019/4/21
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Controller
@RequestMapping("/progress")
public class ProgressTrackController {
    @Resource
    private ProgressTrackService progressTrackService;

    /***
     * 上传数据
     * @param simple
     * @param projectTeam
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/add")
    @ResponseBody
    public ResultInfo uploadAndSave(@RequestParam("simple") String simple, @RequestParam("projectTeam") String projectTeam) {
        ResultInfo resultInfo = new ResultInfo();
        try {
            resultInfo = progressTrackService.json(simple, projectTeam);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultInfo;
    }

    /**
     * 修改数据
     *
     * @param editProject
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/edit")
    @ResponseBody
    public ResultInfo edit(@RequestParam("editProject") String editProject) {
        JSONObject jsonObject = JSONObject.parseObject(editProject);
        ProgressTrack progressTrack = JSONObject.toJavaObject(jsonObject, ProgressTrack.class);
        return progressTrackService.edit(progressTrack);
    }

    /**
     * 查询所有
     *
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/query")
    @ResponseBody
    public List<ProgressTrack> select() {
        return progressTrackService.select();
    }

    /**
     * 删除多条
     *
     * @param list
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/delete")
    @ResponseBody
    public ResultInfo delete(@RequestParam("list") List<String> list) {
        return progressTrackService.delete(list);
    }

    /**
     * 根据项目组查询所有
     *
     * @param project_team
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/queryByProject_team")
    @ResponseBody
    public List<ProgressTrack> selectByProject_team(String project_team,String construction_unit) {
        return progressTrackService.selectByProject_team(project_team,construction_unit);
    }

    /**
     * 按时间查询所有
     *
     * @return ResultInfo 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/queryByTime")
    @ResponseBody
    public List<ProgressTrack> selectByTime(@RequestParam("track") String track) {
        JSONObject jsonObject = JSONObject.parseObject(track);
        ProgressTrack progressTrack = JSONObject.toJavaObject(jsonObject, ProgressTrack.class);
        return progressTrackService.selectByTime(progressTrack);
    }

    /**
     * 通过id查询项目的资金类型
     *
     * @return List集合
     */
    @PostMapping("/queryTypeById")
    @ResponseBody
    public List<String> selectById(@RequestParam("projectId") String id) {
        return progressTrackService.selectProjectById(id);
    }

    /**
     * 项目管理查询
     *
     * @return list
     */
    @PostMapping("/queryByNameAndUnit")
    @ResponseBody
    public List<ProgressTrack> queryByNameAndUnit(@RequestParam(value = "form", required = false) String project) {
        return progressTrackService.queryByNameAndUnit(project);
    }
}
